const e = require("express")
const express=require("express")
const router=express.Router()

const mysql = require("mysql")
const conn = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'root',
    database: "yunheshop",
    port: '3306'
})

//详情页渲染数据
router.get("/product/:id",(req,res)=>{
    let {id}=req.query;
    let sql="select * from midata where id=?";
    conn.query(sql,[id],(err,result)=>{
        if(err){
            console.log("服务器出错");
            return ;
        }
        let data;
        if(result.length){
            data={
                code:0,
                list:result
            }
        }else{
            data={
                code:1,
                msg:"没有该商品的详情"
            }
        }
        res.send(data);
    })
})





module.exports=router;